﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Error;
using System.Reflection;
using DSS_XNA;
using Microsoft.Xna.Framework.Content;
using DSS_XNA.Engine.Actor;

namespace DSS_XNA.Engine.Script.Commands
{
    public static class ScriptCommand_LoadCharacter
    {
        #region Static Methods

        public static void Action(Dictionary<string, string> args, ScriptManager manager, Game1 engine)
        {
            if (!args.ContainsKey("name"))
                throw new DSSException("No name parameter for LoadCharacter");
            if (!args.ContainsKey("fileName"))
                throw new DSSException("No fileName parameter for LoadCharacter");
            if (!args.ContainsKey("x"))
                throw new DSSException("No x parameter for LoadCharacter");
            if (!args.ContainsKey("y"))
                throw new DSSException("No y parameter for LoadCharacter");

            string name = manager.GetParameterValue(args["name"]).ToString();
            string fileName = manager.GetParameterValue(args["fileName"]).ToString();
            int x = Convert.ToInt32(manager.GetParameterValue(args["x"].ToString()));
            int y = Convert.ToInt32(manager.GetParameterValue(args["y"].ToString()));

            IActor actor = Actor.Actor.Create(fileName, engine);
            if (actor == null)
                throw new DSSException(String.Format("Failed to load actor: {0}", name));

            actor.Name = name;

            manager.Engine.CurrentWorld.CurrentWorld.AddActor(actor, x, y);
        }

        #endregion
    }
}
